package cn.hls.entity;

import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import cn.hls.until.GenericsUtils;

/**
 * @fileName: User.java
 * @descrption: 用户实体类
 * @author : yinghui.zhang
 * @Email: uuhui@163.com
 * @date 2015-4-3
 * @version 1.0
 */
@Table(name = "T_USER")
@Entity
@DynamicInsert
@DynamicUpdate
@JsonIgnoreProperties(value={"person"})
public class User extends BaseEntity {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	// 登录名称
	private String loginName;
	// 密码 初始密码为123456
	private String password = "123456";
	private String salt;//密码加密盐值
	// 人员信息
	private Person person;

	@Column(name = "login_name", nullable = false, length = 32)
	public String getLoginName() {
		return loginName;
	}

	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}
	 
	@Column(name = "password", nullable = false, length = 32)
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@OneToOne(fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST,
			CascadeType.MERGE, CascadeType.REFRESH },  optional = true)
	@JoinColumn(name = "person_id")
	@NotFound(action = NotFoundAction.IGNORE)
	public Person getPerson() {
		return person;
	}

	public void setPerson(Person person) {
		this.person = person;
	}

	@Column(name="salt",length=16)
	public String getSalt() {
		return salt;
	}

	public void setSalt(String salt) {
		this.salt = salt;
	}
public static void main(String[] args) {
	String time=new Date().getTime()+"";
	String pwd=GenericsUtils.encrypt(GenericsUtils.encrypt("admin", time),null);
	System.out.println(time);
	System.out.println(pwd);
}
}
